package com.ticket.sass.admin.business.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ticket.sass.admin.business.GroupPurchaseSettingBusiness;
import com.ticket.sass.admin.dto.input.order.group.GroupPurchaseSettingAddInput;
import com.ticket.sass.admin.dto.input.order.group.GroupPurchaseSettingListInput;
import com.ticket.sass.admin.dto.input.order.group.GroupPurchaseSettingUpdInput;
import com.ticket.sass.admin.dto.output.order.group.GroupPurchaseSettingListOutput;
import com.ticket.sass.admin.model.PageModel;
import com.ticket.sass.admin.service.impl.GroupPurchaseSettingsServiceImpl;
import com.ticket.sass.admin.util.ModelUtil;
import com.ticket.sass.common.entity.tenant.GroupPurchaseSettingEntity;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.modelmapper.TypeToken;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ywb
 * @date 2024-08-13 16:04
 */
@Slf4j
@Service
@AllArgsConstructor
public class GroupPurchaseSettingBusinessImpl implements GroupPurchaseSettingBusiness {
    final ModelUtil modelUtil;
    final GroupPurchaseSettingsServiceImpl service;
    
    @Override
    public PageModel<GroupPurchaseSettingListOutput> list(GroupPurchaseSettingListInput input) {
        IPage<GroupPurchaseSettingEntity> page = service.iPage(input);
        List<GroupPurchaseSettingListOutput> outputs = modelUtil.listToList(
            page.getRecords(),
            new TypeToken<List<GroupPurchaseSettingListOutput>>(){}.getType()
        );
        return new PageModel<>(page.getTotal(), outputs);
    }
    
    @Override
    public void upd(GroupPurchaseSettingUpdInput input) {
        GroupPurchaseSettingEntity config = modelUtil.mapToMap(input, GroupPurchaseSettingEntity.class);
        service.updateById(config);
    }
    
    @Override
    public void add(GroupPurchaseSettingAddInput input) {
        GroupPurchaseSettingEntity config = modelUtil.mapToMap(input, GroupPurchaseSettingEntity.class);
        service.save(config);
    }
}
